/**
 * Created by wengms on 2016/9/20.
 */

define(["angular"], function (angular) {

    var DecisionTableModule = angular.module("DecisionTableModule", []);

    DecisionTableModule.controller("DecisionTableController", function ($scope) {

        var columnConfigs = [{
            "columnName":"年龄",
            "conditions":[
                ">0 && < 18",
                ">18 && < 25",
                ">25 && < 30",
                ">30 && < 60"
            ]
        }, {
            "columnName":"婚姻情况",
            "conditions":[
                "已婚",
                "未婚"
            ]
        },{
            "columnName":"学历",
            "conditions":[
                "博士",
                "硕士",
                "本科",
                "专科及以下"
            ]
        },{
            "columnName":"收入",
            "conditions":[
                "<3000",
                "> 3000 && < 5000",
                "> 5000 && < 10000",
                "> 10000"
            ]
        },{
            "columnName":"健康情况",
            'conditions':[
                "良好",
                "不健康"
            ]
        }];

        var conditionLists = [];
        // 先确定前几个数组
        //2个方法参数，1.需要组合的数组，2.已经组合的数组
        var arranging = function(arrangArr,cellArr){
            if (arrangArr.length == 0){
                conditionLists.push(cellArr);
                return cellArr;
            }else{
                var firstArr = arrangArr[0];
                var newArrangArr = arrangArr.slice(1,arrangArr.length);
                _.forEach(firstArr,function(cell){

                    var newCellArr =cellArr.slice(0,cellArr.length);
                    newCellArr.push(cell);
                    arranging(newArrangArr,newCellArr);
                })
            }
        };


        //自动生成组合
        var conditionArrays = _.map(columnConfigs,function(columnConfig){
            return columnConfig.conditions;
        });

        $scope.buildSource = function(){
            conditionLists = [];
            arranging(conditionArrays,[]);
            $scope.conditionLists = conditionLists;
        }
    });








    return DecisionTableModule;
});